<?php
include("../../tools/session.php");
include("../../tools/controls.php");
include("../../conf.php");
include("../../tools/pub.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

/*-- 以下是实际内容 --*/
$page_status = $_POST["page_status"];
$per_page = 20;
if (!$page_status)
{
	include("tpl-inc-wp.php");
	include("../../tools/mysql.php");
	db_connect();
	
	$sql = "SELECT count(log_id) num FROM sys_log";
	$re = db_query_once($sql);
	
	$tpl->assign("wholepage", $re["num"]);
	$tpl->display($oa_tpl_path . "/default/sys_log.html");
}
// 显示 XML
elseif ($page_status == 1)
{
	include("../../tools/mysql.php");
	db_connect();
	
	header("content-type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	echo "<logs>\n";
	
	$page = $_POST["page"];
	$page = ($page == "" || $page <= 0) ? 1 : $page;
   
	$sql = "SELECT b.username, a.suc_status, a.ulogs, a.log_time FROM sys_log a, user b WHERE a.user_id=b.id ORDER BY log_time DESC";
	$re = db_query_page($sql, $page, $per_page);
	
	foreach ($re as $v)
	{
		echo "<item>\n";
		echo "<username><![CDATA[" . $v["username"] . "]]></username>\n";
		echo "<sucstatus>" . $v["suc_status"] . "</sucstatus>\n";
		echo "<ulogs><![CDATA[" . $v["ulogs"] . "]]></ulogs>\n";
		echo "<logtime><![CDATA[" . $v["log_time"] . "]]></logtime>\n";
		echo "</item>\n";
	}

	echo "</logs>\n";
}
?>
